package com.ad_hccm.dao.Appendix;

import com.ad_hccm.domain.Appendix.AE;
import com.ad_hccm.domain.Appendix.SAE;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * TODO 严重不良事件(SAE)报告表
 */
@Mapper
public interface SAEDao {
    @Insert("insert into sae value(#{id}, #{isSAE}, #{type}, #{date}, #{name}, #{birthDate}, #{nation}, #{occurrenceDate}, #{degree}, #{conversion}, #{situation}, #{handle}, #{week})")
    public boolean save(SAE domain);

    @Update("update sae set isSAE = #{isSAE}, type = #{type}, date = #{date}, name = #{name}, birthDate = #{birthDate}, nation = #{nation}, occurrenceDate = #{occurrenceDate}, degree = #{degree}, conversion = #{conversion}, situation = #{situation}, handle = #{handle} where id=#{id} and week=#{week}")
    public boolean update(SAE domain);

    @Select("select * from sae where id=#{id}")
    public List<SAE> getById(String id);

    @Select("select * from sae where id = #{id} and week = #{week}")
    public SAE getWeek(SAE domain);

    @Select("select sae.id id, isSAE, type, date, sae.name name, birthDate, nation, occurrenceDate, degree, conversion, situation, handle, week, patient_user.name idName from sae,patient_user where sae.id = patient_user.id and patient_user.doctorId = #{id}")
    public List<SAE> getAll(String id);

    @Delete("delete from sae where id=#{id} and week=#{week}")
    public boolean delete(SAE domain);

    @Delete("delete from sae where id = #{id} and week>#{week}")
    public boolean deleteBigWeek(SAE domain);

    @Select("select sae.id id, isSAE, type, date, sae.name name, birthDate, nation, occurrenceDate, degree, conversion, situation, handle, week, patient_user.name idName from sae,patient_user where sae.id = patient_user.id and patient_user.doctorId = #{id} and (sae.name like #{search} or patient_user.name like #{search} or type like #{search} or handle like #{search})")
    public List<SAE> search(String search, String id);
}